Skip to content

fix(daemon): close the session app when close omits the app - #4697

Closed
xiatiandeairen wants to merge 2 commits into
callstack:mainfrom
xiatiandeairen:fix/close-active-session-app
Closed

xiatiandeairen wants to merge 2 commits into
callstack:mainfrom
xiatiandeairen:fix/close-active-session-app

Conversation

@xiatiandeairen

@xiatiandeairen xiatiandeairen commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

close without an app ended the session but left the app running on iOS simulators and Android emulators, although help close says it closes the active session app. The daemon now closes the session's appBundleId the same way close <app> does, Android close fences included.

  • A session that never opened an app still closes without a platform close.
  • Web sessions are unchanged.
  • The positional-only gate predates feat: bridge web provider to agent-browser #826, which added only the web exception. I found no decision to skip the session app.

9 files: 1 source file (+13/-4), the rest tests and integration fakes.

Fixes #4684

Validation

Head 09181458e on base aa600e980.

  • The new unit test fails on base and passes on head. Provider integration: 79/79 files pass. check:quick passed.
  • check:affected --run --head 09181458e: all stages pass except unit. 21 of its 22 failures pass when re-run alone. The remaining one, android-sdk-setup-action.test.ts, fails the same way on aa600e980 on this host, where a local Android SDK path leaks into the expected path.
  • iOS 27.2 simulator: after open → close, MultiTodo stays in launchctl on base and is gone on head.
  • Android emulator: pidof 4746 → 4746 on base, 3382 → empty on head.
  • Sessions that opened no app close with exit 0 on both.

Impact to review: a plain close now also stops the app on macOS, on physical Apple devices, on cloud providers, at the end of .ad scripts, and in replay test suite teardown (closeReplayTestSession). Teardown adds Android close-fence time per flow. None of these were run live.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

close without an app ended the session but skipped the platform close, so
the app kept running on iOS simulators and Android emulators although close
help says it closes the active session app. A native session with an app now
closes that app the same way close <app> does, Android close fences included.
A session that never opened an app still closes without a platform close.
…app close

Plain close now stops the session app, so the scripted Android providers
report the app gone after force-stop, the repair close scenario reuses the
shared repair world instead of its own copy, and the Maestro suite counts
the stop that each flow's session close adds.
@thymikee

Copy link
Copy Markdown
Member

Thanks for the fix. At 0918145, plain close now dispatches a platform close for every native session with an app, and the PR only shows live runs for an iOS simulator and an Android emulator, with no transcript attached. Only one check is reported for this fork head, and no unit, integration or device job ran against it. Before merge, we need live evidence for the two routes below and a CI run on the head.

The new dispatch in session-close.ts:84 reaches routes that were never run. A macOS native app-device session now runs closeMacOsApp, which quits the app and polls, and can throw COMMAND_FAILED or MACOS_APP_TERMINATION_TIMEOUT. A physical iOS device now runs closeAppleApplication, then closeIosApp, then terminateApp, through CoreDevice or the XCTest runner. If either fails, plain close throws and keeps the session, claim and lease. Before this change, close succeeded on these devices. That matters because close is the cleanup step of every agent loop and of replay test teardown. Please attach live output at 0918145 for two runs. (a) macOS native app device: open <app> --platform macos --session s, then plain close --session s. Show exit 0, Closed: s, and the app process gone (pgrep or lsappinfo), with no app-device-scope error. (b) Physical iOS with the CoreDevice backend: open <bundle> --udid <udid>, then plain close. Show exit 0, the app absent from xcrun devicectl device info processes, and the close wall time. If a device is missing, please say so. Please also link or attach the output of the simulator and emulator runs from the PR body.

Not blocking, and you can take or leave these: the repair-armed close receipt at session-close.ts:100 is still keyed on the request positionals, while the platform operation now comes from platformCloseTarget, so an untargeted close that fails to commit and a retry with the same app dispatch the platform close twice, and keying the receipt on the resolved target would skip the repeat (the test would then expect one call, plus a case for a differently targeted retry); comments in request-router-typed-error.test.ts (lines 195-196 and 230) and session-replay-repair-transaction-close-ordering.test.ts (lines 99 and 188) still say an untargeted close is a no-op and cite the removed shouldDispatchPlatformClose, and dispatchTargetedPlatformClose at session-close.ts:198 now dispatches without a target, so the comments (and optionally the name) could say a session with no app dispatches no platform close; close --shutdown at session-close-lifecycle-teardown.ts:102 now runs the full session-app close, with Android fences of up to 2s + 10s + 2s, right before the device is shut down, so either time it next to base in the Android evidence or skip the app close when the same close shuts down a local owner; and the PR impact list could add one sentence that replay test teardown now surfaces a close failure and that close --save-script on a repair-armed session now dispatches a platform close before the commit.

@thymikee

Copy link
Copy Markdown
Member

On the two live runs from my last comment (a macOS native app device, and a physical iOS device with CoreDevice): if you have either device, please run that sequence at this head and post the output. If you're missing one or both, reply here and say which. A maintainer will then run the missing route on their device, so the PR won't wait on hardware you don't have.

@xiatiandeairen

Copy link
Copy Markdown
Contributor Author

Closing this one. Thanks for the careful review.

We don't need the behavior change ourselves: our runs now always pass the app to close. Changing plain close would also affect macOS sessions, physical devices, providers and replay test teardown, so it shouldn't land on our evidence alone.

The mismatch in #4684 still stands: help close says an omitted app closes the session app, while the code only ends the session. Whether to change the code or the help is your call, so I'm leaving the issue open.

@xiatiandeairen

Copy link
Copy Markdown
Contributor Author

I ran the two routes from your comment live at 0918145, and I re-ran the simulator and emulator cases. Each run used base aa600e9 and head 0918145, in that order, on the same device, with a fresh daemon state directory each time.

(a) macOS native app (com.apple.calculator, not running before the test)

open … --platform macos --session s close --session s Calculator after close
base Opened, exit 0, pid 57291 Closed: s, exit 0 still running (pgrep -x Calculator → 57291)
head Opened, exit 0, pid 57880 Closed: s, exit 0, 0.8 s gone (pgrep empty, lsappinfo empty)
head, re-run exit 0 Closed: s, exit 0, 0.8 s gone

No app-device-scope, COMMAND_FAILED or MACOS_APP_TERMINATION_TIMEOUT error appeared. One base close took 13.6 s, and a base re-run took 0.5 s. I did not look into the slow one. It happened on base, so it is not from this change.

(b) Physical iOS device, CoreDevice backend (iPhone 17, iOS 27.2 24B119, developer-signed com.todoapp.ios)

open … --udid <udid> --session s close --session s xcrun devicectl device info processes after close
base Opened, exit 0, pid 5130 Closed: s, exit 0, 0.4 s still running (pid 5130)
head Opened, exit 0, pid 5148 Closed: s, exit 0, 0.9 s absent

Simulator and emulator runs from the PR body (re-run)

Device Before close After close --session s
base iOS simulator, com.apple.Preferences 1 UIKitApplication: entry in launchctl list still 1 entry, exit 0
head iOS simulator 1 entry 0 entries, exit 0
base Android emulator, com.android.settings pidof 4523 still 4523, exit 0, 0.5 s
head Android emulator pidof 4619 empty, exit 0, 0.8 s

Not covered. I did not time close --shutdown. It shuts down the device, and these simulators and emulators come from a host pool that other agents use. The other non-blocking notes are also not done yet: the repair-armed receipt keyed on the positionals, the stale shouldDispatchPlatformClose comments, and the impact sentence. CI on this fork head still needs a maintainer to approve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

close without an app ends the session but leaves the app running

2 participants